package learning.Test;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class User implements Runnable {
	public static void main(String[] args) {
		User u = new User();
		Thread t = new Thread(u);
		t.start();
	}

	@Override
	public void run() {
		try {
			Socket s = MySocket.joinLocalWeb();
			OutputStream os = s.getOutputStream();
			InputStream is = s.getInputStream();
			String srData = "12,13,14";
			System.out.println(srData);
			os.write(srData.getBytes());
			os.flush();
			int b = 0;
			String str = "";
			while ((b = is.read()) != -1) {
				str += (char) b;
			}
			System.out.println("Area=" + str);
			os.close();
			is.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public User() {
	}
}

class MySocket extends Socket {
	public static synchronized Socket joinLocalWeb() {
		try {
			return new Socket("127.0.0.1", 2222);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
